
********************************************************************************
************************************* Round 1 **********************************
********************************************************************************

	clear all
	set more off
	set maxvar 15000
		
	use "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_data\nels88_by_hs.dta",clear
	rename *, lower
	
	/*Keep Public Schools*/
	keep if g8ctrl==1
	 	
	/* Base year variables: 1: Father's Education 2: Mother's Education 
	3: Family Income 4: Child's Race 5: Child's Gender */
	
	gen survey=1988
	label var survey "Survey Year"
	
	ren  trnregon region
	label var region "schools' region"
	
	gen wave=2
	label var wave "Survey time: (2 Years Aft HS)"
	gen weight=f2qwt
	
	rename (bys34b  bys34a byp80 byp10 bys12 byqwt ) ///
	(mot_edu fat_edu fam_inc race_by sex_by by_weight)
	
	recode mot_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8/98=.)
		
	gen mot_hs=mot_edu>=1 if mot_edu~=.
	
	recode fat_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8/98=.)
	
	gen fat_hs=fat_edu>=1 if fat_edu~=.
	
	label var mot_hs "Dummy: 1 if respondent's mother graduted from a HS"
	label var fat_hs "Dummy: 1 if respondent's father graduted from a HS"
	
	recode fam_inc (1=0) (2=1000) (3=2999) (4=4999) (5=7499) (6=9999) ///
	(7=14999) (8=19999) (9=24999) (10=34999) (11=49999) (12=74999) ///
	(13=99999) (14=199999) (15=300000) (98=.)
	
	replace fam_inc=(237/113.6)*fam_inc
	
	label var fam_inc "Family income adjusted for inflation"
	
	recode race_by (6/8=.)
	gen white=race_by==4 if race_by~=.
	gen black=race_by==3 if race_by~=.
	gen hispanic=race_by==2 if race_by~=.
	gen oth_race=race_by==1|race_by==5 if race_by~=.
	
	recode sex_by (7/8=.)
	gen female=sex_by==2 if sex_by~=.
	
	gen not_white=.
	replace not_white=1 if black==1|hispanic==1|oth_race==1
	replace not_white=0 if white==1
	
	label var white "Dummy: 1 if respondent is a white"
	label var black "Dummy: 1 if respondent is black"
	label var hispanic "Dummy: 1 if respondent is hispanic"
	label var oth_race "Dummy: 1 if respondent is other race"
	label var female "Dummy: 1 if respondent is female"
	
	*********** High School
	recode f2s6b (8/9=.)
	gen hs1_high_sch=f2s6b==1 if f2s6b~=.
	label var hs1_high_sch "Dummy: 1 if repondent has a HS diploma"
	
	
	** The following voluntary type questions have been asked recent HS grad
	 rename f2s37 hs_com_vol_2yrs
	 recode hs_com_vol_2yrs (6/8=.)
	 
	 gen hs_yes_com_vol_2yrs=hs_com_vol_2yrs==1 if hs_com_vol_2yrs~=.
	 label var hs_yes_com_vol_2yrs ///
	 "Dummy: 1 During the past 2 yrs, have you perform any vol or com serv work"
	 
	*1 Voluntary Particapation
	gen vltnry_prtcptn1=1 if hs_yes_com_vol_2yrs==1
	replace vltnry_prtcptn1=0 if hs_yes_com_vol_2yrs==0
	label var vltnry_prtcptn1 ///
	"Dummy:1 if respondent ever involved in voluntary activities"
	
	keep survey wave stu_id sch_id mot_hs fat_hs white black hispanic ///
	oth_race female fam_inc vltnry_prtcptn1 weight hs1_high_sch byses ///
	region not_white hs1_high_sch
	
**************************************************************************************
	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round1.dta", replace

********************************************************************************
******************************** Round 2 ***************************************
********************************************************************************
	clear all
	set more off
	set maxvar 15000
	
	use "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_data\nels88_2yrs_aft_hs.dta",clear
	rename *, lower
	
	/*Keep Public Schools*/
	keep if g8ctrl==1
	
	gen survey=1988
	gen wave=2
	
	ren  trnregon region
	label var region "schools' region"
	
	gen weight=f3qwt
	rename (bys34b  bys34a byp80 byp10 bys12) (mot_edu fat_edu fam_inc race_by sex_by )
	
	recode mot_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8/98=.)
	gen mot_hs=mot_edu>=1 if mot_edu~=.
	
	recode fat_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8/98=.)	
	gen fat_hs=fat_edu>=1 if fat_edu~=.
	
	label var fat_hs "Dummy: 1 if respondent's father graduted from a HS"
	label var mot_hs "Dummy: 1 if respondent's mother graduted from a HS"
	
	recode fam_inc (1=0) (2=1000) (3=2999) (4=4999) (5=7499) (6=9999) ///
	(7=14999) (8=19999) (9=24999) (10=34999) (11=49999) (12=74999) (13=99999) ///
	(14=199999) (15=300000) (98=.)
	
	replace fam_inc=(237/113.6)*fam_inc
	label var fam_inc "Family income adjusted for inflation"
	
	recode race_by (6/8=.)
	gen white=race_by==4 if race_by~=.
	gen black=race_by==3 if race_by~=.
	gen hispanic=race_by==2 if race_by~=.
	gen oth_race=race_by==1|race_by==5 if race_by~=.
	
	recode sex_by (7/8=.)
	gen female=sex_by==2 if sex_by~=.
	
	gen not_white=.
	replace not_white=1 if black==1|hispanic==1|oth_race==1
	replace not_white=0 if white==1
	
	label var white 	"Dummy: 1 if respondent is a white"
	label var black		"Dummy: 1 if respondent is black"
	label var hispanic  "Dummy: 1 if respondent is hispanic"
	label var oth_race  "Dummy: 1 if respondent is other race"
	label var female    "Dummy: 1 if respondent is female"
	
* The following voluntary type questions have been asked 2 year after HS grad

    recode volunte1 (-9=.) (-8=.) (-6=.)
	gen hs2_yes_youth_vol=volunte1==1 if volunte1~=.
	label var hs2_yes_youth_vol ///
	"Dummy: 1 Volunteered for a youth organization"
	
	recode volunte2 (-9=.) (-8=.) (-6=.)
	gen hs2_yes_serv_vol=volunte2==1 if volunte2~=.
	label var hs2_yes_serv_vol ///
	"Dummy: 1 Volunteered for a service organization"
	
	recode volunte3 (-9=.) (-8=.) (-6=.)
	gen hs2_yes_political_vol=volunte3==1 if volunte3~=.
	label var hs2_yes_political_vol ///
	"Dummy: 1 Volunteered for a political organization"
	
	recode volunte4 (-9=.) (-8=.) (-6=.)
	gen hs2_yes_church_vol=volunte4==1 if volunte4~=.
	label var hs2_yes_church_vol ///
	"Dummy: 1 Volunteered for a church organization"
	
	recode volunte5 (-9=.) (-8=.) (-6=.)
	gen hs2_yes_hosp_vol=volunte5==1 if volunte5~=.
	label var hs2_yes_hosp_vol ///
	"Dummy: 1 Volunteered for a hospital organization"
	
	recode volucmty (-9=.) (-8=.) (-6=.)
	gen hs2_yes_comm_vol=volucmty==1 if volucmty~=.
	label var hs2_yes_comm_vol ///
	"Dummy: 1 Volunteered for a community organization"
	
	recode volunte6  (-8=.) (-6=.)
	gen hs2_yes_sport_vol=volunte6==1 if volunte6~=.
	label var hs2_yes_sport_vol ///
	"Dummy: 1 Volunteered for a sports organization"
	
	recode volunte7  (-8=.) (-6=.)
	gen hs2_yes_educ_vol=volunte7==1 if volunte7~=.
	label var hs2_yes_educ_vol ///
	"Dummy: 1 Volunteered for an educational organization"
	
	recode volunte8 (-9=.) (-8=.) (-6=.)
	gen hs2_yes_othr_vol=volunte8==1 if volunte8~=.
	label var hs2_yes_othr_vol ///
	"Dummy: 1 Volunteered for a other organization"
	
	egen volunteer=rowmax(hs2_yes_youth_vol hs2_yes_serv_vol ///
	hs2_yes_political_vol hs2_yes_church_vol hs2_yes_hosp_vol ///
	hs2_yes_comm_vol hs2_yes_sport_vol hs2_yes_educ_vol hs2_yes_othr_vol)
	
	recode f3volunt (-9=.) (-6=.)
	
	recode hrsvlntr (-9=.) (-8=.) (-6=.) (-7=.) (-4=.)
	replace hrsvlntr=0 if f3volunt==0&hrsvlntr==.

	*************************************
	recode  f3volunt (-6=.)
	
	****** Voting questions in 1994 (2 years after high school)
	recode f3rgvote (-6=.)
	gen hs2_yes_reg_vote=f3rgvote==1 if f3rgvote~=.
	label var hs2_yes_reg_vote "Vote: Registered to Vote"
	
	recode  f3diplom (-6=0)
	gen hs2_high_sch= f3diplom==1 if  f3diplom~=.
	label var hs2_high_sch "Dummy: 1 if repondent has a HS diploma"
	
	recode   f3psenum (2=1) (3=1) (4=1) (5=1)
	gen hs2_att_PSE= f3psenum==1 if  f3psenum~=.
	label var hs2_att_PSE "Dummy: 1 ever attanded PSE institution"
	
********************************************************************************
	/* NELS 1988 Recent High School Grad Round 2: */
	
	*	Voluntary Hours 
	gen vlntry_hours=hrsvlntr
	sum vlntry_hours, detail
	replace vlntry_hours=r(p99) if vlntry_hours>r(p99)&vlntry_hours~=.
	label var vlntry_hours "Number of voluntary hours in a month"
	
	*	Voluntary Particapation
	gen vltnry_prtcptn=1 if vlntry_hours>0&vlntry_hours~=.
	replace vltnry_prtcptn=0 if vlntry_hours==0&vlntry_hours~=.
	
	replace vltnry_prtcptn=volunteer if vltnry_prtcptn==.|vltnry_prtcptn==0
	label var vltnry_prtcptn ///
	"Dummy:1 if respondent ever involved in voluntary activities"
	
	*	Voting Registration
	gen register_vote=hs2_yes_reg_vote==1 if hs2_yes_reg_vote~=.
	label var register_vote "Vote: Registered to Vote"
	
	*	Postsecondary Education
	gen post_scndry=1 if hs2_att_PSE==1 
	replace post_scndry=0 if hs2_att_PSE==0
	label var post_scndry "Dummy: 1 ever attanded PSE institution"
	
	keep  survey wave stu_id sch_id mot_hs fat_hs white black hispanic ///
	oth_race female vltnry_prtcptn post_scndry fam_inc ///
	register_vote vlntry_hours weight region not_white hs2_high_sch
	
*******************************************************************

	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round2", replace

********************************************************************************
******************************** Round 3 ***************************************
********************************************************************************
	clear all
	set more off
	set maxvar 15000
	
	******* Obtaining school id for round 3
	use "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round1.dta", clear
	
	keep sch_id stu_id 
	
	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round1_stu_id.dta", replace
	
	clear all
	set more off
	set maxvar 15000
	
	use "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_data\nels88_8yrs_aft_hs.dta"
	rename *, lower
	
	merge 1:1 stu_id using ///
	"C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round1_stu_id.dta"
	
	keep if _merge==3
	drop _merge
	
	/*Keep Public Schools*/
	keep if g8ctrl==1
	
	gen survey=1988
	gen wave=3
	
	ren  trnregon region
	replace region=. if region==-9
	label var region "schools' region"
	
	gen weight=f4qwt
	
	rename (bys34b  bys34a byp80 byp10 bys12) ///
	(mot_edu fat_edu fam_inc race_by sex_by )
		
	recode mot_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8/98=.)
	gen mot_hs=mot_edu>=1 if mot_edu~=.
	
	recode fat_edu (1=0) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8/98=.)	
	gen fat_hs=fat_edu>=1 if fat_edu~=.
	
	label var mot_hs "Dummy: 1 if respondent's mother graduted from a HS"
	label var fat_hs "Dummy: 1 if respondent's father graduted from a HS"
	
	recode fam_inc (1=0) (2=1000) (3=2999) (4=4999) (5=7499) (6=9999) ///
	(7=14999) (8=19999) (9=24999) (10=34999) (11=49999) (12=74999) ///
	(13=99999) (14=199999) (15=300000) (98=.)
	
	replace fam_inc=(237/113.6)*fam_inc //multiplying with the deflator
	label var fam_inc "Family income adjusted for inflation"
	
	recode race_by (6/8=.)
	gen white=race_by==4 if race_by~=.
	gen black=race_by==3 if race_by~=.
	gen hispanic=race_by==2 if race_by~=.
	gen oth_race=race_by==1|race_by==5 if race_by~=.
	
	recode sex_by (7/8=.)
	gen female=sex_by==2 if sex_by~=.
	
		gen not_white=.
		replace not_white=1 if black==1|hispanic==1|oth_race==1
		replace not_white=0 if white==1
	
	label var white "Dummy: 1 if respondent is a white"
	label var black "Dummy: 1 if respondent is black"
	label var hispanic "Dummy: 1 if respondent is hispanic"
	label var oth_race "Dummy: 1 if respondent is other race"
	label var female "Dummy: 1 if respondent is female"
	
	recode f4att4yr (-9=.) (-3=.)
	gen hs8_att_4_yr_PSE=f4att4yr==1 if f4att4yr~=.
	label var hs8_att_4_yr_PSE "Dummy: 1 ever attanded a 4-year institution"
	
	recode f4attpse (-9=.) (-3=.)
	gen hs8_att_PSE=f4attpse==1 if f4attpse~=.
	label var hs8_att_PSE "Dummy: 1 ever attanded PSE institution"
	
    **** Voting questions in 2000 (8 years after high school)
	recode f4irvote (-7=.) (-2=.) (-1=.)
	gen hs8_yes_reg_vote=f4irvote==1 if f4irvote~=.
	label var hs8_yes_reg_vote "Vote: Registered to Vote"
	
   ** The following voluntary type questions asked 8 years after HS grad 
	
	recode f4iyouth (-7=.) (-2=.) (-1=.)
	gen hs8_yes_youth_vol=f4iyouth==1 if f4iyouth~=.
	label var hs8_yes_youth_vol "Youth organization volunteer"
	
	recode f4icivic (-7=.) (-2=.) (-1=.)
	gen hs8_yes_civic_vol=f4icivic==1 if f4icivic~=.
	label var hs8_yes_civic_vol "Civic organization volunteer"

	
	* Voluntary Particapation
	egen vltnry_prtcptn=rowmax(hs8_yes_youth_vol hs8_yes_civic_vol)
	label var vltnry_prtcptn ///
	"Dummy:1 if respondent ever involved in voluntary activities"
	
	* Voting Registration
	gen register_vote=1 if hs8_yes_reg_vote==1
	replace register_vote=0 if hs8_yes_reg_vote==0
	label var register_vote "Vote: Registered to Vote"
	
	
	* Postsecondary Education
	gen post_scndry=1 if hs8_att_PSE==1 
	replace post_scndry=0 if hs8_att_PSE==0
	
	label var post_scndry "Dummy: 1 ever attanded PSE institution"
	
	keep survey wave stu_id  mot_hs fat_hs white black hispanic ///
	oth_race female  vltnry_prtcptn post_scndry register_vote ///
	fam_inc weight sch_id region not_white
	
****************************************************************************
	*********************************************************************
	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round3", replace

********************************************************************************
********* Merging with district IDs that comes in a different file *************
********************************************************************************
	
	clear all
	set more off
	set maxvar 15000

	use "C:\Users\EAsker\Desktop\ReducedForm_ABR\ReducedForm\RF_ReShape\RF_NELS88\RFNELS88_data\scmeg_rev.dta", clear

	rename *, lower
********************************************************************************************

	keep sch_id f1sch_id f2sch_id byncesid f1ncesid f2ncesid byqedtyp f1qedtyp f2qedtyp  byqedstc f1qedstc f2qedstc
	order sch_id f1sch_id f2sch_id byncesid f1ncesid f2ncesid byqedtyp f1qedtyp f2qedtyp  byqedstc f1qedstc f2qedstc
	sort sch_id
	
	drop if byncesid==""
	keep sch_id byncesid byqedtyp byqedstc
	
	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\by_ncesid_c.dta", replace

	merge 1:m sch_id using "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round1"
	
	drop if _merge~=3
	drop _merge
	
	gen fips_state=substr(byncesid,1,2)
	destring fips_state,replace
	
	replace byncesid=substr(byncesid,1,7)
	destring byncesid, replace
	
	drop byqedtyp byqedstc 
		
	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Merged_data\nels88_merged_round1.dta" ,replace	
********************************************************************************

	clear all
	set more off
	set maxvar 15000

	use "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_data\scmeg_rev.dta", clear
	 
	rename *, lower
********************************************************************************************

	keep sch_id f1sch_id f2sch_id byncesid f1ncesid f2ncesid byqedtyp f1qedtyp f2qedtyp  byqedstc f1qedstc f2qedstc
	order sch_id f1sch_id f2sch_id byncesid f1ncesid f2ncesid byqedtyp f1qedtyp f2qedtyp  byqedstc f1qedstc f2qedstc
	sort sch_id
	
	drop if byncesid==""
	keep sch_id byncesid byqedtyp byqedstc
	
	merge 1:m sch_id using "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round2" 
	
	drop if _merge~=3
	drop _merge
	
	
	gen fips_state=substr(byncesid,1,2)
	destring fips_state,replace
	
	replace byncesid=substr(byncesid,1,7)
	destring byncesid, replace
	
	drop byqedtyp byqedstc 
	
	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Merged_data\nels88_merged_round2.dta" ,replace	
	
	****************************************
	
	clear all 
	set more off
	
	use "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Merged_data\nels88_merged_round1.dta"
	
	merge 1:1 stu_id using "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Merged_data\nels88_merged_round2.dta"
	drop _merge
	
	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Merged_data\nels88_merged_round_1_2.dta",replace
	
	***********************************************************************************************

	clear all
	set more off
	set maxvar 15000

	 use "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_data\scmeg_rev.dta", clear
	 
	 rename *, lower
********************************************************************************************

	keep sch_id f1sch_id f2sch_id byncesid f1ncesid f2ncesid byqedtyp f1qedtyp f2qedtyp  byqedstc f1qedstc f2qedstc
	order sch_id f1sch_id f2sch_id byncesid f1ncesid f2ncesid byqedtyp f1qedtyp f2qedtyp  byqedstc f1qedstc f2qedstc
	sort sch_id
	
	drop if byncesid==""
	keep sch_id byncesid byqedtyp byqedstc
	
	merge 1:m sch_id using "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\nels88_round3" 
	
	drop if _merge~=3
	drop _merge
	
	gen fips_state=substr(byncesid,1,2)
	destring fips_state,replace
	
	replace byncesid=substr(byncesid,1,7)
	destring byncesid, replace
	
	drop byqedtyp byqedstc 
	
	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Merged_data\nels88_merged_round3.dta" ,replace	
	
	*************************************
	
	clear all
	set more off
	
	use "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Merged_data\nels88_merged_round_1_2.dta"
	
	append  using "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Merged_data\nels88_merged_round3.dta" 
	
	rename byncesid ncesid

	/* High school graduation status is determined by combining surveys 
	conducted in the summer after 12th grade and two years later.*/
	gen high_school=hs1_high_sch
	replace high_school=hs2_high_sch if (high_school==.|high_school==0)&hs2_high_sch~=.
	replace high_school=hs2_high_sch if hs2_high_sch~=.&high_school==.

	save "C:\Users\EAsker\Desktop\ABR\nels_88\RFNELS88_Clean_data\RFNELS88",replace
	
	
	

	
	
	
	
	
	